package com.aaa.bbb.mymaintain.service.impl;

import com.aaa.bbb.mymaintain.entity.Employee;
import com.aaa.bbb.mymaintain.entity.IssuesManager;
import com.aaa.bbb.mymaintain.dao.IssuesManagerDao;
import com.aaa.bbb.mymaintain.service.IssuesManagerSer;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author max
 * @since 2023-11-03
 */
@Service
public class IssuesManagerSerImpl extends ServiceImpl<IssuesManagerDao, IssuesManager> implements IssuesManagerSer {

    @Override
    public PageInfo<Map<String, Object>> queryPagerByCond(String state,int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = baseMapper.selectProblem(state);
        String qianzhui="../../../src/assets/";
        for(Map<String, Object> item : list){
            String url = item.get("picture").toString();
            String explanation = item.get("explanation").toString();
            String[] temp;
            String[] temp1;
            String delimiter = ";";// 指定分割字符
            temp = url.split(delimiter);// 分割字符串
            temp1 = explanation.split(delimiter);
            for(int i=0;i<temp.length;i++){
                temp[i] = qianzhui+temp[i];
            }
            item.put("picture",temp);
            item.put("explanation",temp1);
        }
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Map<String, Object>> queryPagerByParam(String name, String gender, String state, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = baseMapper.selectInfo(name,gender,state);
        String qianzhui="../../../src/assets/";
        for(Map<String, Object> item : list){
            String url = item.get("picture").toString();
            String explanation = item.get("explanation").toString();
            String[] temp;
            String[] temp1;
            String delimiter = ";";// 指定分割字符
            temp = url.split(delimiter);// 分割字符串
            temp1 = explanation.split(delimiter);
            for(int i=0;i<temp.length;i++){
                temp[i] = qianzhui+temp[i];
            }
            item.put("picture",temp);
            item.put("explanation",temp1);
        }
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void updateIssueManager(String issue_id,String state,String reason){
        baseMapper.updateProblem(issue_id,state,reason);
    }

    @Override
    public void updateFund1(String issue_id,String state,String reason){
        baseMapper.updateFund2(issue_id,state,reason);
    }

    @Override
    public List<Map<String,Object>> getPerson1() {
        return baseMapper.selectPerson();
    }

    @Override
    public void assignPerson1(String issue_id,String maintenance_id) {
        baseMapper.updateMantenanceId(issue_id,maintenance_id);
    }

    @Override
    public void updatePersist1(String issue_id, String state, String reason) {
        baseMapper.updatePersist2(issue_id,state,reason);
    }
}
